/*************************************************
* Title：TinyToolKit
* Author：Opportunity 
* Describe：
* CreateTime：2020-07-08 17:43:08
* Version：1.0
* Modify Recorder：
*************************************************/

using System.IO;
using UnityEditor;
using TinyToolKit;
using UnityEngine;

namespace TinyToolKitEditor
{
    [CustomEditor(typeof(TinyToolSettingAsset))]  
    public class TinyToolSettingAssetEditor : Editor
    {
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginDisabledGroup(true);
            base.OnInspectorGUI();
            EditorGUI.EndDisabledGroup();
        }
    
        public static void CreateAsset()
        {
            string dirPath = "Assets/Resources";
            if (Directory.Exists(dirPath) == false)
                Directory.CreateDirectory(dirPath);

            string filePath = Path.Combine(dirPath, "TinyToolSetting.asset");
            if (File.Exists(filePath))
            {
                if (EditorUtility.DisplayDialog("警告", "TinyToolSetting已经创建，确定替换吗？", "确定", "取消"))
                    Create(filePath);
            }
            else
            {
                Create(filePath);
            }
        }

        private static void Create(string filePath)
        {
            TinyToolSettingAsset asset = CreateInstance<TinyToolSettingAsset>();
            AssetDatabase.CreateAsset(asset, filePath);
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = asset;
        }
    }
}
